import env from './env';

import { OpenAI } from 'openai';
import type { ChatCompletionMessageParam } from 'openai/resources/index.mjs';

const client = new OpenAI({
  apiKey: env.KIMI_API_KEY,
  baseURL: 'https://api.moonshot.cn/v1',
});

const genText = async (messages: ChatCompletionMessageParam[]) => {
  const completion = await client.chat.completions.create({
    model: 'moonshot-v1-8k',
    messages,
    temperature: 0.5,
  });
  return completion.choices[0]?.message?.content ?? '';
};

export default {
  genText,
};
